/**
 * 
 */
package org.tuestudent.grouppa;

import java.util.HashMap;
import java.util.Map;

/**
 * @author s121170 Class for initializing whole application (run by LoginScreen
 *         Activity)
 */
public class Main {

    // context available for everyone
    private static AppContext context;
    private static TCPClient connection;
    private static Map<String, ViewController> controllers;
    private static PeriodicUpdater updater;

    private static boolean initialized = false;

    /**
     * This method is supposed to initialize the application should
     */
    public static void initializeApp() {
        if (initialized)
            return;
        // CHECK: Create TCPClient connection
        connection = TCPClient.getInstance();
        // CHECK: Create AppContext
        context = new AppContext();
        // TODO: Create and start periodic updater
        // CHECK: Create view controllers
        controllers = new HashMap<String, ViewController>();
        controllers.put("ChatView", ChatViewController.getInstance());
        controllers.put("GroupView", GroupViewController.getInstance());
        controllers.put("PlanningView", new PlanningViewController());
        controllers.put("WallView", WallViewController.getInstance());
        controllers.put("LoginView", LoginViewController.getInstance());
        context.setCurrentViewController(LoginViewController.getInstance());

    }

    /**
     * Getter for a specific controller
     * 
     * @param name
     *            name of controller to get
     * @return controller reference
     */
    public static ViewController getController(String name) {
        // TODO: get a controller from map
        return controllers.get(name);
    }

    /**
     * Getter for connection class
     * 
     * @return connection
     */
    public static TCPClient getConnection() {
        return connection;
    }

    /**
     * Getter for context
     * 
     * @return context
     */
    public static AppContext getContext() {
        return context;
    }

    
    public static PeriodicUpdater getUpdater() {
        return updater;
    }

    public static void setUpdater(PeriodicUpdater updater2) {
        updater = updater2;
        
    }

    public static void resetControllers() {
        for( ViewController controller : controllers.values())
        {
            controller.reset();
        }
    }
}
